package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyContent;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：攻略详情控制器
 *
 * @package: cn.wolfcode.trip.admin.controller
 * @author: Patch
 * @date: 2019/5/24 16:15
 * 总结:
 */
@Controller
@RequestMapping("strategyDetail")
public class StrategyDetailController {
    @Autowired
    private IStrategyDetailService detailService;
    @Autowired
    private IStrategyService strategyService;
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo) {
        model.addAttribute("pageInfo", detailService.query(qo));
        model.addAttribute("strategys", strategyService.listAll(null));
        return "strategyDetail/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyDetail detail) {
        JsonResult result = new JsonResult();
        try {
            detailService.saveOrUpdate(detail);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("亲，操作失败，请重试");
        }
        return result;
    }

    @RequestMapping("getContentById")
    @ResponseBody
    public StrategyContent getContentById(Long id){
       return detailService.getContentById(id);
    }
}
